#include "stdio.h"
#include "board.h"
#include "FreeRTOS.h"
#include "task.h"
#include "mod_eth.h"
#include "ethuser.h"

#include "platform.h"
#include "data.h"
#include "shell.h"
#include "mod_emeter.h"
#include "mod_rfcard.h"
#include "mod_gprs.h"

#include "port.h"
#include "adc.h"
#include "mod_led.h"

#include "dev.h"
#include "charger.h"
#include "gtc_client.h"

#include "qrencode.h"
void test(void *para){
   
  while(1)
	{ 
     os_msleep(1000);		
		 printf("test test test test\r\n");
		
    }
}

#include "fsapi.h"
void test_readline(void){
    fs_fd fd;
    fs_open(&fd,"charge/test.txt", (uint32_t)FS_O_RDWR | (uint32_t)FS_O_CREAT);
    #if 0
    char_t buf[100]={0};
    int32_t num = fs_read_line(&fd, buf, sizeof(buf));
    while(num > 0){
        printf("%s\r\n", buf);
        memset(buf, 0, sizeof(buf));
        num = fs_read_line(&fd, buf, sizeof(buf));
    }
    #endif
    fs_close(&fd);
}

int main(void)
{
    INTX_ENABLE();
    
    board_init(NULL);
    
    printf("\r\nsystem begin\r\n");
#if 0
    W25QXX_Init(); 
    W25QXX_Erase_Chip();
    printf("erase chip success\r\n");
    while(1);
#endif 
	
	#if 1
    if (data_init() != 0){
        goto fail;
    }
    if (dev_init() != 0){
        goto fail;
    }
    if (charger_init() != 0){
        goto fail;
    }
    if (pro_client_init() != 0){
        goto fail;
    }
    if (shell_init() != 0){
        goto fail;
    }
    #endif
    //xTaskCreate(test,                   (const char *)"test",        configMINIMAL_STACK_SIZE*15,         NULL,   1,       NULL);
  
    vTaskStartScheduler();		
fail:
    printf("sys init fail!!!\n");
    while(1);   
}

